<template>
	<view v-model="currentId" :items="items" class="__spec_item" :optionKey="optionKey">
		<view class="__spec_item__title">{{spec}}</view>
		<view class="__spec_item__option flex-x">
			<view @tap="choose" :id="item.unid" v-for="(item,index) in items" :key="index"
				:class="[(currentId == item.unid ? 'option__active' : '')]">{{item.spec_detail}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentId: ''
			}
		},
		props: {
			spec: String,
			items: Array,
			optionKey: [Number,String]
		},
		methods: {
			choose: function(event) {
				this.currentId = event.currentTarget.id
			}
		},
		watch: {
			currentId: function(newId, oldId) {
				this.$emit('event', newId, this.optionKey)
			}
		}
	}
</script>

<style>
	.__spec_item {
		padding: 30rpx;
	}

	.__spec_item .__spec_item__title {
		font-size: 28rpx;
		line-height: 40rpx;
		color: #333333;
	}

	.__spec_item__option view {
		font-size: 28rpx;
		line-height: 40rpx;
		background-color: #E7E7E7;
		color: #999999;
		padding: 10rpx 26rpx;
		margin: 12rpx 16rpx 0 0;
		border-radius: 30rpx;
	}

	.__spec_item__option .option__active {
		background-color: #E6B873;
		color: #FFFFFF;
	}
</style>
